package com.yoda.mall.mysql.api;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.mall.api.HomeAdvertiseApi;
import com.yoda.mall.model.entity.sms.Coupon;
import com.yoda.mall.model.entity.sms.FlashPromotionProductRelation;
import com.yoda.mall.model.entity.sms.HomeAdvertise;
import com.yoda.mall.mysql.mapper.HomeAdvertiseMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

@DubboService
public class HomeAdvertiseApiImpl implements HomeAdvertiseApi {
    @Autowired
    private HomeAdvertiseMapper homeAdvertiseMapper;

    @Override
    public void createAdvertise(HomeAdvertise homeAdvertise) {
        homeAdvertiseMapper.insert(homeAdvertise);
    }

    @Override
    public void deleteAdvertiseByIds(List<Long> ids) {
        homeAdvertiseMapper.deleteBatchIds(ids);
    }

    @Override
    public Page<HomeAdvertise> getAdvertiseListPage(LocalDateTime endTime, String name, Integer type, Integer pageNum, Integer pageSize) {
        Page<HomeAdvertise> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<HomeAdvertise> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotEmpty(endTime), HomeAdvertise::getEndTime, endTime);
        lqw.like(StrUtil.isNotEmpty(name), HomeAdvertise::getName, name);
        lqw.eq(ObjectUtil.isNotNull(type), HomeAdvertise::getType, type);
        return homeAdvertiseMapper.selectPage(page, lqw);
    }

    @Override
    public void updateAdvertise(HomeAdvertise homeAdvertise) {
        homeAdvertiseMapper.updateById(homeAdvertise);
    }

    @Override
    public HomeAdvertise getAdvertiseById(Long id) {
        return homeAdvertiseMapper.selectById(id);
    }
}
